package HDFS;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class makefile {

    //创建文件名a.txt，并在里面协上hello world
    public void makefile() throws URISyntaxException, IOException, InterruptedException {
        Configuration con = new Configuration();

        FileSystem fileSystem = FileSystem.get(new URI("hdfs://192.168.7.99:9000"),
                con, "root");

        FSDataOutputStream fsDataOutputStream = fileSystem.create(new Path("hdfs/test/a.txt"));

        fsDataOutputStream.write("hello world".getBytes());
        fsDataOutputStream.flush();
        fsDataOutputStream.close();

        fileSystem.close();
    }
}
